package com.yanfan.zutai.controller;

import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.iot.domain.Device;
import com.yanfan.zutai.aop.SysInitData;
import com.yanfan.zutai.aop.SysInitUpdateData;
import com.yanfan.zutai.aop.SysQueryData;
import com.yanfan.zutai.domain.BDeviceVideo;
import com.yanfan.zutai.service.IBDeviceVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 视频监控Controller
 *
 * @author ruoyi
 * @date 2023-11-06
 */
@RestController
@RequestMapping("/zutai/bDeviceVideo")
public class BDeviceVideoController extends BaseController {
    @Autowired
    private IBDeviceVideoService bDeviceVideoService;

    /**
     * 查询视频监控列表
     */
    // //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceVideo:list')")
    @GetMapping("/list")
    @SysQueryData
    public TableDataInfo list(BDeviceVideo bDeviceVideo) {
        startPage();
        List<BDeviceVideo> list = bDeviceVideoService.selectBDeviceVideoList(bDeviceVideo);
        return getDataTable(list);
    }

    /**
     * 查询组态视频监控列表
     */
    // //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceVideo:list')")
    @GetMapping("/listzt")
    @SysQueryData
    public TableDataInfo listzt(String ztGuid) {
        startPage();
        List<Device> list = bDeviceVideoService.selectBDeviceVideoLists(ztGuid);
        return getDataTable(list);
    }

    /**
     * 导出视频监控列表
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceVideo:export')")
    @Log(title = "视频监控", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BDeviceVideo bDeviceVideo) {
        List<BDeviceVideo> list = bDeviceVideoService.selectBDeviceVideoList(bDeviceVideo);
        ExcelUtil<BDeviceVideo> util = new ExcelUtil<BDeviceVideo>(BDeviceVideo.class);
        util.exportExcel(response, list, "视频监控数据");
    }

    /**
     * 获取视频监控详细信息
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceVideo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bDeviceVideoService.selectBDeviceVideoById(id));
    }

    /**
     * 新增视频监控
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceVideo:add')")
    @Log(title = "视频监控", businessType = BusinessType.INSERT)
    @PostMapping
    @SysInitData
    public AjaxResult add(@RequestBody BDeviceVideo bDeviceVideo) {
        return toAjax(bDeviceVideoService.insertBDeviceVideo(bDeviceVideo));
    }

    /**
     * 修改视频监控
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceVideo:edit')")
    @Log(title = "视频监控", businessType = BusinessType.UPDATE)
    @PutMapping
    @SysInitUpdateData
    public AjaxResult edit(@RequestBody BDeviceVideo bDeviceVideo) {
        return toAjax(bDeviceVideoService.updateBDeviceVideo(bDeviceVideo));
    }

    /**
     * 删除视频监控
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceVideo:remove')")
    @Log(title = "视频监控", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bDeviceVideoService.deleteBDeviceVideoByIds(ids));
    }

    /**
     * 刷新token
     */
    @Log(title = "刷新token", businessType = BusinessType.INSERT)
    @PostMapping(value = "/refreshToken")
    public AjaxResult refreshToken() {
        bDeviceVideoService.refreshAllToken();
        return AjaxResult.success();
    }

    /**
     * 设备excel导入模板下载
     */
    @PostMapping("/importTemplate")
    @ResponseBody
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<BDeviceVideo> util = new ExcelUtil<BDeviceVideo>(BDeviceVideo.class);
        util.importTemplateExcel(response, "视频监控");
    }

    /**
     * 设备excel导入
     */
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<BDeviceVideo> util = new ExcelUtil<BDeviceVideo>(BDeviceVideo.class);
        List<BDeviceVideo> deviceList = util.importExcel(file.getInputStream());
        String message = bDeviceVideoService.importData(deviceList);
        return AjaxResult.success(message);
    }
}
